﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace XNAGame_Lab1
{
    class SpriteMenu
    {
        private Texture2D[] _Texture;

        public Texture2D[] Texture
        {
            get { return _Texture; }
            set { 
                _Texture = value;
                _nTexture = _Texture.Length;
                _iTexture = 0;
                _Width = _Texture[0].Width;
                _Height = _Texture[0].Height;

            
            }
        }
        private int _nTexture;

        public int nTexture
        {
            get { return _nTexture; }
            set { _nTexture = value; }
        }

        
        private int _iTexture;

        public int iTexture
        {
            get { return _iTexture; }
            set { _iTexture = value; }
        }
        private double _Left;

        public double Left
        {
            get { return _Left; }
            set { _Left = value; }
        }
        private double _Top;

        public double Top
        {
            get { return _Top; }
            set { _Top = value; }
        }
        private double _Width;

        public double Width
        {
            get { return _Width; }
            set { _Width = value; }
        }
        private double _Height;

        public double Height
        {
            get { return _Height; }
            set { _Height = value; }
        }

        public SpriteMenu(Texture2D[] texture, double left, double top)
        {
            Texture = texture;
            Left = left;
            Top = top;
        }
        public void Update(GameTime gameTime)
        {
            _iTexture = (_iTexture + 1) % _nTexture;
            if (State == 1)
            {
                if (Math.Abs(delta1) >= 10)
                    delta2 *= -1;
                delta1 += delta2;
            }
        }

        double delta1 = 1;
        double delta2 = 1;

        public void Draw(GameTime gameTime, SpriteBatch spritePatch)
        {
            if (State == 0)
                spritePatch.Draw(_Texture[_iTexture], new Vector2((float)_Left, (float)_Top), Color.White);
            else
            {
                Rectangle destRec = new Rectangle((int)(Left - delta1), (int)(Top - delta1),(int)(Width+2*delta1),(int)(Height+2*delta1));
                spritePatch.Draw(_Texture[_iTexture], destRec, Color.White);
            }

        }

        public bool IsSelected(double x, double y)
        {
            if (x < _Left || x >= _Left + _Width)
                return false;
            if (y < _Top || y >= _Top + _Height)
                return false;
            return true;
        }
        private int _state = 0;

        public int State
        {
            get { return _state; }
            set { _state = value; }
        }

    }
}
